#coding=utf-8
#author=haishan09@gmail.com
import json
from django.db import models
from custom.fields import JsonifyConfigField, FontawesomeField


class Chart(models.Model):
    name = models.CharField('名称', max_length=64)
    label = models.CharField('说明', max_length=64)
    icon = FontawesomeField('图标', default='fa-line-chart', max_length=64)
    default_config = JsonifyConfigField('默认配置', blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __unicode__(self):
        return self.label

    @property
    def dconf(self):
        return json.loads(self.default_config or '{}')

